﻿using System;
using System.Globalization;

namespace RaisingStudio.SmallProgram.Library
{
    [SmallProgramType]
    public static class Text
    {
        public static Primitive Append(Primitive text1, Primitive text2)
        {
            return (((string)text1) + ((string)text2));
        }

        public static Primitive ConvertToLowerCase(Primitive text)
        {
            if (text.IsEmpty)
            {
                return text;
            }
            return ((string)text).ToLower(CultureInfo.CurrentUICulture);
        }

        public static Primitive ConvertToUpperCase(Primitive text)
        {
            if (text.IsEmpty)
            {
                return text;
            }
            return ((string)text).ToUpper(CultureInfo.InvariantCulture);
        }

        public static Primitive EndsWith(Primitive text, Primitive subText)
        {
            if (text.IsEmpty || subText.IsEmpty)
            {
                return 0;
            }
            return ((string)text).EndsWith((string)subText);
        }

        public static Primitive GetCharacter(Primitive characterCode)
        {
            int num = (int)characterCode;
            char c = (char)num;
            return c.ToString();
        }

        public static Primitive GetCharacterCode(Primitive character)
        {
            if (character.IsEmpty)
            {
                return 0;
            }
            return (Primitive)character[0];
        }

        public static Primitive GetIndexOf(Primitive text, Primitive subText)
        {
            if (text.IsEmpty)
            {
                return 0;
            }
            if (subText.IsEmpty)
            {
                return 0;
            }
            return (((string)text).IndexOf((string)subText) + 1);
        }

        public static Primitive GetLength(Primitive text)
        {
            if (text.IsEmpty)
            {
                return 0;
            }
            return ((string)text).Length;
        }

        public static Primitive GetSubText(Primitive text, Primitive start, Primitive length)
        {
            if (text.IsEmpty || start > ((string)(text)).Length || start < 1 || start.IsEmpty || length.IsEmpty)
            {
                return "";
            }
            if (start + length <= ((string)(text)).Length)
            {
                return ((string)(text)).Substring(start - 1, length);
            }
            return ((string)(text)).Substring(start - 1);
        }

        public static Primitive GetSubTextToEnd(Primitive text, Primitive start)
        {
            if (text.IsEmpty || start > ((string)(text)).Length || start < 1 || start.IsEmpty)
            {
                return "";
            }
            return ((string)(text)).Substring(start - 1);
        }

        public static Primitive IsSubText(Primitive text, Primitive subText)
        {
            if (text.IsEmpty || subText.IsEmpty)
            {
                return 0;
            }
            return ((string)text).Contains((string)subText);
        }

        public static Primitive StartsWith(Primitive text, Primitive subText)
        {
            if (text.IsEmpty || subText.IsEmpty)
            {
                return 0;
            }
            return ((string)text).StartsWith((string)subText);
        }
    }
}

